﻿using HighThroughput.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Ozone.Views.Widget
{
    /// <summary>
    /// UCValveSwtich.xaml 的交互逻辑
    /// </summary>
    /// 
    public delegate void DelegateValveSwtich(string tag);

    public partial class UCValveSwtich : UserControl
    {

        private int nONIndex = 0;
        private List<Button> lstButtons = new List<Button>();
        public DelegateValveSwtich DelegateDone_;
        public UCValveSwtich()
        {
            InitializeComponent();
            lstButtons.Add(btn1);
            lstButtons.Add(btn2);
            lstButtons.Add(btn3);
            lstButtons.Add(btn4);
        }

        public void setCallBack(DelegateValveSwtich d)
        {
            DelegateDone_ = d;
        }

        public void setType(int nType)
        {
            if(nType == 0)
            {
                btn1.Width = 60;
                btn2.Width = 60;
                btn3.Visibility = Visibility.Collapsed;
                btn4.Visibility = Visibility.Collapsed;
            }
        }

        public void setStatus(int nIndex)
        {
            if (nIndex == nONIndex)
                return;

            nONIndex = nIndex;
            for (int i = 0; i < lstButtons.Count; i++)
            {
                if (nIndex == i)
                    lstButtons[i].Background = Tools.getColor("Brush_PurpleBackColor");
                else
                    lstButtons[i].Background = Tools.getColor("Brush_MainBackColor");
            }
        }

        private void buttonSwitch_click(object sender, RoutedEventArgs e)
        {
            string tag = ((Button)sender).Tag.ToString();

            if (tag == nONIndex.ToString())
                return;

            setStatus(OSSUtility.Utility.str2int(tag));

            DelegateDone_(tag);
        }
    }
}
